package cn.easyar.samples.helloarqrcode;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import cn.easyar.samples.helloarqrcode.bean.UserStatusBean;
import cn.easyar.samples.helloarqrcode.xunfei.VoiceBean;
import cn.easyar.samples.helloarqrcode.xunfei.VoiceOrder;


public class DCSActivity extends Activity {

    ImageView ivDcs;
    Button btn_back;
    TextView tv_toolbar_center;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去除title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //去掉Activity上面的状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_dcs);
        EventBus.getDefault().register(this);
        VoiceOrder.activityList.add("DCSActivity");
        context = this;
        tv_toolbar_center = (TextView) findViewById(R.id.tv_toolbar_center);
        ivDcs = (ImageView) findViewById(R.id.iv_dcs);
        btn_back = (Button) findViewById(R.id.btn_back);
        tv_toolbar_center.setText("DCS页面");
        ivDcs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(context, WarnActivity.class);
                startActivity(it);
            }
        });
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void voiceEvent(VoiceBean voiceBean) {
        if(voiceBean.str.contains(VoiceOrder.VOICE_QUIT)&&VoiceOrder.activityList.get(VoiceOrder.activityList.size()-1).equals("DCSActivity")){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    VoiceOrder.activityList.remove(VoiceOrder.activityList.size()-1);
                    finish();
                }
            });
        }else if(voiceBean.str.contains(VoiceOrder.VOICE_SEE_WARN)){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Intent it = new Intent(context, WarnActivity.class);
                    startActivity(it);
                }
            });
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
